package com.acorn.community.common.utils;

import java.util.regex.Pattern;

/**
 * 格式校验工具
 * @author yurl
 */
public class CheckUtils {
    public static boolean isMobile(String mobile) {
        String regex = "^1\\d{10}$";

        if(mobile==null||mobile.length()<=0){
            return false;
        }
        return Pattern.matches(regex, mobile);
    }

    public static boolean isEmail(String email) {
        String regex = "^(\\w+([-.][A-Za-z0-9]+)*){3,18}@\\w+([-.][A-Za-z0-9]+)*\\.\\w+([-.][A-Za-z0-9]+)*$";

        if(email==null||email.length()<=0){
            return false;
        }
        return Pattern.matches(regex, email);
    }


    public static boolean isPassword(String password) {
        // 密码必须在6到12个字符之间，且至少包含一个字母和一个数字
        String regex = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$";
        if (password==null||password.length()<=0) {
            return false;
        }
        return Pattern.matches(regex, password);
    }
}
